package com.example.yiqinmanagersystem.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.yiqinmanagersystem.entity.User;
import com.example.yiqinmanagersystem.mapper.RoleMapper;
import com.example.yiqinmanagersystem.mapper.UserMapper;
import com.example.yiqinmanagersystem.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/*
 **@Author:youpeng
 **Created on 2022/9/14
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Resource
    private UserMapper userMapper;

    @Resource
    private RoleMapper roleMapper;

    @Override
    public User login(String username, String password) {
        User user = userMapper.login(username, password);
        return user;
    }

    @Override
    public void saveUserRole(Integer uid, Integer[] ids) {
        roleMapper.deleteRoleUserByUid(uid);
        if(ids!=null && ids.length>0){
            for (Integer rid : ids) {
                roleMapper.saveUserRole(uid,rid);
            }
        }
    }

    @Override
    public User selectUserByUsername(String username) {
        return userMapper.selectUserByUsername(username);
    }
}
